package site.yunnong.atvris.common.exception;

import org.springframework.util.CollectionUtils;
import site.yunnong.atvris.common.api.ResultCodeEnum;

import java.util.Collection;

/**
 * 自定义断言抽象类，为避免与框架重复，加了Local前缀
 * @author JinghaoZhang
 * @date 2021年-05月-07日
 */
public abstract class LocalAssert {

    public static void notNull(Object object, String message) {
        if (object != null) {
            throw new YunnongBusinessException(ResultCodeEnum.ERROR_BUSINESS, message);
        }
    }

    public static void isNull(Object object, String message) {
        if (object != null) {
            throw new YunnongBusinessException(ResultCodeEnum.ERROR_BUSINESS, message);
        }
    }

    public static void notZero(int count, String message) {
        if (count == 0) {
            throw new YunnongBusinessException(ResultCodeEnum.ERROR_BUSINESS, message);
        }
    }

    public static void notEmpty(Collection<?> collection, String message) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new YunnongBusinessException(ResultCodeEnum.ERROR_BUSINESS, message);
        }
    }
}
